package com.itheima.server.controller;

import com.itheima.server.service.SettingsService;
import com.itheima.tanhua.model.vo.SettingsVo;
import com.itheima.tanhua.model.domain.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {
    @Autowired
    private SettingsService settingsService;

    /**
     * 通用设置
     * @return
     */
    @GetMapping("/settings")
    public ResponseEntity settings() {
        SettingsVo settingsVo = settingsService.settings();

        return ResponseEntity.ok(settingsVo);

    }

    /**
     * 设置陌生人问题
     * @param map
     * @return
     */
    @PostMapping("/questions")
    public ResponseEntity saveQuestions(@RequestBody Map map){
        String txt = (String) map.get("content");
        //调用service进行陌生人问题的保存或者修改
        settingsService.saveQuestions(txt);

        return ResponseEntity.ok(null);
    }

    @GetMapping("/blacklist")
    public ResponseEntity blacklist(Integer page,Integer pagesize){
        PageResult pageResult = settingsService.blacklist(page, pagesize);

        return ResponseEntity.ok(pageResult);
    }

    /**
     * 通知设置
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody Map map) {
        //获取参数
        settingsService.saveSettings(map);
        return ResponseEntity.ok(null);
    }
}
